package org.sang.mapper;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.ResultMap;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.SelectProvider;
import org.sang.bean.User;
import org.sang.bean.Role;
import org.sang.mapper.provider.UserProvider;

import java.util.List;

/**
 * Created by sang on 2017/12/28.
 */
@Mapper
public interface UserMapper {
    User loadUserByUsername(String username);

    List<Role> getRolesByUserId(Long id);

    @Insert("INSERT INTO user(workno,name,phone,telephone,address,username,password,userface) VALUES " +
                "(#{workNo}, #{name}, #{phone},#{telephone}, #{address}, #{username},#{password}, #{userface})")
    int userReg(User user);

    List<User> getUsersByKeywords(@Param("keywords") String keywords);

    int updateUser(User user);

    int deleteRoleByUserId(Long userId);

    int addRolesForUser(@Param("userId") Long userId, @Param("rids") Long[] rids);

    User getUserById(Long userId);

    int deleteUser(Long userId);

    List<User> getAllUser(@Param("currentId") Long currentId);

    @SelectProvider(type = UserProvider.class, method = "queryUserParam")
    @ResultMap("org.sang.mapper.UserMapper.BaseResultMap")
    List<User> getUsers(User user);

    @Select("SELECT count(*) FROM user WHERE workno = #{workNo}")
    int getCountByworkNo(String workNo);
}
